package com.situ.mvc.controller;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.situ.mvc.entity.Student;
import com.sun.org.apache.xerces.internal.util.SynchronizedSymbolTable;

import jdk.nashorn.internal.ir.annotations.Reference;

// /student/add.action
@Controller
@RequestMapping(value="/student")
public class StudentController {
	
	@RequestMapping(value = "/getStudentAddPage")
	public String name() {
		return "student_add";
	}
	
	/*@RequestMapping(value = "/add")
	public ModelAndView name(Student student) {
		ModelAndView modelAndView = new ModelAndView();
		modelAndView.addObject("student", student);
		modelAndView.setViewName("student_info");
		return modelAndView;
	}*/
	@RequestMapping(value = "/add")
	public String name(Student student,Model model) {
		model.addAttribute("student", student);
		return "student_info";
	}
	
	@RequestMapping(value="/add4")
	public String add4(String name, Integer age, String gender, Model model){
		model.addAttribute("name", name);
		model.addAttribute("age", age);
		model.addAttribute("gender", gender);
		return "student_info";
	}
	
	@RequestMapping(value = "/deleteAllPage")
	public String deleteAllPage(){
		return "deleteall";
	}
	
	@RequestMapping(value = "/deleteAll")
	public void deleteAll(Integer[] ids, HttpServletRequest request){
		String[] idArray = request.getParameterValues("ids");
		System.out.println(Arrays.toString(idArray));
		System.out.println(Arrays.toString(ids));
	}
	
	@RequestMapping(value = "/zhuanChong")
	public String zhuanChong(){
//		return "forward:/student/pageList.action";
		return "redirect:/student/pageList.action";
	}
	
	@RequestMapping(value = "/pageList")
	public String pageList(Model model){
		ArrayList<Student> list = new ArrayList<>();
		Student studen1 = new Student("张三", 24, "男");
		Student studen2 = new Student("李四", 26, "男");
		list.add(studen1);
		list.add(studen2);
		model.addAttribute("list", list);
		return "student_info";
	}
	
	@RequestMapping(value = "/list")
	@ResponseBody
	public List<Student> findList(){
		List<Student> list = new ArrayList<>();
		for (int i = 0; i < 100; i++) {
			Student student = new Student(i, "张三" + i, 24, "男");
			list.add(student);
		}
		return list;
	}
	
	@RequestMapping(value = "/list2")
	@ResponseBody
	public Student findList2(){
		Student student = new Student(1, "李四", 26, "男");
		return student;
	}
	
	@RequestMapping(value = "/list3")
	@ResponseBody
	public boolean list3(){
		boolean isExist = true;
		return isExist;
	}
	
	@RequestMapping(value = "/page")
	public void page(@RequestParam(value="pageNNN")Integer pageNo,Integer pageSize){
		System.out.println("pageNo:  " + pageNo);
		System.out.println("pageSize:  " + pageSize);
	}
	
}
